package com.kill.service;

import com.common.entity.Kill;
import com.common.entity.Rsp;
import com.kill.mapper.KillMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class KillServiceImpl {

    @Autowired
    private KillMapper killMapper;

    @Autowired
    RedisServiceImpl redisService;

    public Rsp addMany(List<Kill> kills){
        Integer result = killMapper.addMany(kills);
        return result == kills.size()?Rsp.success(kills):Rsp.fail().msg("添加失败");
    }

    public Rsp findByGoodsId(String goodsId){
        Kill result = killMapper.findByGoodsId(goodsId);
        return result != null?Rsp.success(result):Rsp.fail().msg("查询失败");
    }

    public Rsp findAll() {
        List<Object> kills = redisService.lRange("kill", 0L, 1L);
        return Rsp.success(kills);
    }
}
